﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _2017._02._02.PracticeWork
{
    class Program
    {
        static void Main(string[] args)
        {
            TV tvset = new TV(3);
            tvset.SwitchChannelUp();
            Console.ReadKey();
        }
    }


    class Channel
    {
        private int channelNumber = 0;
        private string channelName;

        public int ChannelNumber
        {
            get { return channelNumber; }
            private set
            {
                if (value < 0)
                    throw new ArgumentOutOfRangeException();
                channelNumber = value;
            }
        }

        public string ChannelName
        {
            get { return channelName; }
            private set
            {
                channelName = value;
            }
        }

        public Channel()
        {
            Console.WriteLine("Enter number of channel: ");
            ChannelNumber = Int32.Parse(Console.ReadLine());
            Console.WriteLine("Enter name of channel: ");
            ChannelName = Console.ReadLine();
        }
    }

    class TV
    {
        private int currentChannel;
        private List<Channel> channels = new List<Channel>();

        public TV(int numbers)
        {
            for (int i = 0; i < numbers; i++)
            {
                Channel channel = new Channel();
                channels.Add(channel);
            }
            currentChannel = channels.Count();
        }


        public int SwitchChannelUp()
        {
            foreach (var channel in channels)
            {
                if (currentChannel == channels.Count())
                    currentChannel = channels.LastIndexOf(channels.First());
                else if (currentChannel == channel.ChannelNumber)
                    currentChannel++;
            }
            ShowCurrentChannel(++currentChannel);
            return currentChannel;
        }

        public int SwitchChannelDown()
        {
            foreach (var channel in channels)
            {
                if (currentChannel == channels.LastIndexOf(channels.First()))
                    currentChannel = channels.LastIndexOf(channels.Last());
                else if (currentChannel == channel.ChannelNumber)
                    currentChannel--;
            }
            ShowCurrentChannel(--currentChannel);
            return currentChannel;
        }

        public void ShowCurrentChannel(int currentChannel)
        {
            foreach (var channel in channels)
            {
                if (currentChannel == channel.ChannelNumber)
                {
                    Console.WriteLine("Номер канала: {0}", channel.ChannelNumber);
                    Console.WriteLine("Название канала: {0}", channel.ChannelName);
                }
            }
        }

    }

}
